package org.example.module_login.utlis;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 响应类（ R ）
 *
 * @author HAJ
 * @since 2025-03-03 15:17:42
 */
@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R {

    // 响应编码: 1成功，0和其它数字为失败
    private Integer code;

    // 提示信息
    private String msg;

    // 响应数据
    private Object data;

    /**
     * 操作成功
     * */
    public static R ok(String msg) {
        return R.builder().code(1).msg(msg).build();
    }

    /**
     * 操作失败
     * */
    public static R error(String msg) {
        return R.builder().code(0).msg(msg).build();
    }

    /**
     * 返回数据
     * */
    public static R data(Object data) {
        return R.builder().code(1).data(data).build();
    }

    /**
     * 分页查询数据
     * */
    public static R page(Long total, Object records) {
        Map<String, Object> data = new HashMap<>();
        data.put("records", records);
        data.put("total", total);
        return R.builder().code(1).data(data).build();
    }

}














